#ifndef HALL_SENSOR_LIB_H
#define HALL_SENSOR_LIB_H

#include "foc_utils.h"
#include "stdint.h"
#include "Simple_Sensor.h"
// seq 1 > 5 > 4 > 6 > 2 > 3 > 1     000 001 010 011 100 101 110 111
typedef uint8_t (*HallState)(void);
typedef struct
{
	// the current 3bit state of the hall sensors
	int8_t hall_state;
	// the current sector of the sensor. Each sector is 60deg electrical
	int8_t electric_sector;
	
	long electric_rotations;
	
	Direction direction;
	Direction old_direction;

  int cpr;
	float velocity_max;
	long pulse_diff;
	long pulse_timestamp;
	HallState getHallState;
}Simple_HallSensor_t;

void HallSensor_init(Simple_HallSensor_t *handle,uint8_t pp);

int32_t HallSensor_getFullRotations(Simple_HallSensor_t *handle);
double HallSensor_getPreciseAngle(Simple_HallSensor_t *handle);
float HallSensor_getSensorAngle(Simple_HallSensor_t *handle);
float HallSensor_getAngle(Simple_HallSensor_t *handle);
float HallSensor_getVelocity(Simple_HallSensor_t *handle);
float HallSensor_getMechanicalAngle(Simple_HallSensor_t *hanle);
void HallSensor_updateState(Simple_HallSensor_t *handle,uint8_t state);
#endif
